package com.eboss2.sbs.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.eboss2.sbs.R;
import com.eboss2.sbs.activity.base.BaseActivity;
import com.eboss2.sbs.adapter.LogisticsDetailListAdapter;
import com.eboss2.sbs.config.Config;
import com.eboss2.sbs.model.ExpressOutDTO;
import com.eboss2.sbs.model.LogisticsList;
import com.mytools.tool.activityManager.MyActivityManager;
import com.mytools.tool.views.MyListView;
import com.tool.utils.utils.ToastUtils;
import com.tool.utils.view.MyScrollView;

import java.util.ArrayList;
import java.util.List;

public class MyLogisticsDetailActivity extends BaseActivity implements View.OnClickListener{

	private MyScrollView pullToRefreshScrollView;
	private MyListView listview;
	private List<LogisticsList> datas = new ArrayList<>();
	private LogisticsDetailListAdapter adapter;
	private ExpressOutDTO expressOutDTO;
	private int page = 1;
	private int rows = Config.ROWS;

	private TextView tv_status_name;
	private TextView tv_ems_no;
	private TextView tv_ems_content;




	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		mContext = this;
		setContentView(R.layout.activity_my_logistics_detail);
		MyActivityManager.getInstance().addActivity(this);
		initView();

		expressOutDTO = (ExpressOutDTO) getIntent().getSerializableExtra("logisticsDetail");
		if (expressOutDTO != null && expressOutDTO.getData() != null && expressOutDTO.getData().size() > 0){
			datas.clear();
			datas.addAll(expressOutDTO.getData());
			adapter.notifyDataSetChanged();
		}else{
			ToastUtils.showShort(mContext, "暂无物流信息");
			onBackPressed();
			return;
		}
	}

	private void initView(){
		showView(R.id.titleback_btn_back, true);
		setTvText(R.id.tv_title, "物流详情");
		showView(R.id.next_sure, false);
		findViewById(R.id.titleback_btn_back).setOnClickListener(this);

		tv_status_name = textView(R.id.tv_status_name);
		tv_ems_no = textView(R.id.tv_ems_no);
		tv_ems_content = textView(R.id.tv_ems_content);


		pullToRefreshScrollView = (MyScrollView) findViewById(R.id.pullToRefreshScrollView);
//		pullToRefreshScrollView.setOnRefreshListener(new MyLogisticsDetailActivity.MyOnRefreshListener());
//		pullToRefreshScrollView.setMode(PullToRefreshBase.Mode.BOTH);
		listview = (MyListView)findViewById(R.id.listview);
//		listview.setOnItemClickListener(this);




		adapter = new LogisticsDetailListAdapter(this,datas);
		listview.setAdapter(adapter);


//		testData();

	}

	private void testData() {
		tv_status_name.setText("运送中");
		tv_ems_no.setText("中通快递（1913210100001）");
		tv_ems_content.setText("以下信息由物流公司提供，如无跟踪信息或有疑问，请查中通快递官方网站或联系其公示电话");

		for (int i = 0; i < 5; i++){
			LogisticsList logisticsList = new LogisticsList();
			logisticsList.setTime("2017-12-21 12:12:33");
			logisticsList.setContext("[武汉市] [中吉武汉仓]的鑫源泽数码专营店已收件 电话:17742032635");
			datas.add(logisticsList);
		}
		adapter.notifyDataSetChanged();
	}


//	@Override
//	public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
////		startActivity(new Intent(mContext, MyMachtInviteDetailActivity.class));
//	}
//
//
//	class MyOnRefreshListener implements PullToRefreshBase.OnRefreshListener2<ScrollView> {
//		@Override
//		public void onPullDownToRefresh(PullToRefreshBase<ScrollView> refreshView) {
//			pullToRefreshScrollView.setMode(PullToRefreshBase.Mode.BOTH);
//			String label = DateUtils.formatDateTime(mContext, System.currentTimeMillis(), DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL);
//			refreshView.getLoadingLayoutProxy().setLastUpdatedLabel(label);
//			refreshData();
//		}
//		@Override
//		public void onPullUpToRefresh(PullToRefreshBase<ScrollView> refreshView) {
//			page++;
//			getdata();
//		}
//	}


	private void refreshData(){
		datas.clear();
		page = 1;
		getdata();
	}

	private void getdata(){
//		Map<String, Object> params = new HashMap<String, Object>();
////		params.put("sid", mApp.getLoginEntity().getSid());
////		String key = getTvText(R.id.tv_search_key);
////		if(!StringUtil.isNull(key)){params.put("key", key);}
////		else{params.put("key", "");}
//		params.put("pagenum", page);
//		params.put("pagesize", rows);
//		API.http_post(this, API.COUPON_LIST, params, new HttpCallback<CouponListEntity>(this) {
//			@Override
//			public void onSuccess(int statusCode, CouponListEntity data) {
//				if(data!=null){
//					List<CouponEntity> tmp_datas = data.getCoupons();
//					if(tmp_datas==null||tmp_datas.size()==0||tmp_datas.size()<rows){
//						if(tmp_datas==null||tmp_datas.size()==0){
//							toast("没有更多数据");
//						}
//						pullToRefreshScrollView.setMode(PullToRefreshBase.Mode.PULL_DOWN_TO_REFRESH);
//					}
//					if(tmp_datas!=null&&tmp_datas.size()>0){
//						datas.addAll(tmp_datas);
//					}
//				}
//				boolean no_datas = (datas==null||datas.size()==0);
//				showView(R.id.eva_nodata, no_datas);
//				showView(R.id.listview, !no_datas);
//				adapter.notifyDataSetChanged();
//				pullToRefreshScrollView.onRefreshComplete();
//			}
//
//			@Override
//			public void onFailure(int code, String message) {
//				pullToRefreshScrollView.onRefreshComplete();
//				super.onFailure(code, message);
//
//			}
//
//			@SuppressWarnings({ "unchecked", "rawtypes" })
//			@Override
//			public TypeToken getTypeToken() {
//				return new TypeToken<CouponListEntity>() {
//				};
//			}
//		});
	}





	@Override
	public void onClick(View v) {
		switch (v.getId()) {
			case R.id.titleback_btn_back:
				finish();
				break;

			default:break;
		}
	}

	
}
